home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / fbm12s.lha / fbedge.c < prev    next >
C/C++ Source or Header  |  1994-07-18  |  3KB  |  115 lines

  1. /*****************************************************************
  2.  * fbedge.c: FBM Release 1.2 07-Apr-93 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989-1993 by Gary Sherwin & Michael Mauldin.
  5.  * Permission is granted to use this file in whole or in part for
  6.  * any purpose, educational, recreational or commercial, provided
  7.  * that this copyright notice is retained unchanged.  This software
  8.  * is available to all free of charge by anonymous FTP and in the
  9.  * UUNET archives.
  10.  *
  11.  *
  12.  * fbedge.c: Take derivative and edge detect image
  13.  *
  14.  * USAGE
  15.  *      % fbedge [ flag ] < image > image2
  16.  *
  17.  * EDITLOG
  18.  *      LastEditDate = Mon Jun 25 00:55:55 1990 - Michael Mauldin
  19.  *      LastFileName = /usr2/mlm/src/misc/fbm/fbedge.c
  20.  *
  21.  * HISTORY
  22.  * 07-Apr-93  Michael Mauldin (mlm) at Carnegie-Mellon University
  23.  *    Added -J switch
  24.  *
  25.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  26.  *    Package for Release 1.0
  27.  *
  28.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  29.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  30.  *
  31.  * 07-Nov-88  Gary W. Sherwin (sherwin) at Westinghouse R&D
  32.  *    Changed to fbedge.
  33.  *
  34.  * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  35.  *    Created.
  36.  *****************************************************************/
  37.  
  38. # include <stdio.h>
  39. # include <math.h>
  40. # include "fbm.h"
  41.  
  42. # define USAGE "Usage: fbedge [ -t<threshhold> ] < bitmap > bitmap"
  43.  
  44. #ifndef lint
  45. static char *fbmid =
  46. "$FBM fbedge.c <1.2> 07-Apr-93 (C) 1989-1993 by Gary Sherwin & \
  47. Michael Mauldin, source code available free from MLM@CS.CMU.EDU \
  48. and from UUNET archives$";
  49. #endif
  50.  
  51. main (argc, argv)
  52. char *argv[];
  53. { int w, h, k;
  54.   int blacktrp = 0;
  55.   int outtype = DEF_1BIT;
  56.   FBM input, output;
  57.  
  58.   /* Get the options */
  59.   while (--argc > 0 && (*++argv)[0] == '-')
  60.   { while (*++(*argv))
  61.     { switch (**argv)
  62.       { case 't':    blacktrp = atoi (*argv+1); SKIPARG; break;
  63.     case 'A':    outtype = FMT_ATK; break;
  64.     case 'B':    outtype = FMT_FACE; break;
  65.     case 'F':    outtype = FMT_FBM; break;
  66.     case 'G':    outtype = FMT_GIF; break;
  67.     case 'I':    outtype = FMT_IFF; break;
  68.     case 'J':    outtype = FMT_JPEG; break;
  69.     case 'L':    outtype = FMT_LEAF; break;
  70.     case 'M':    outtype = FMT_MCP; break;
  71.     case 'P':    outtype = FMT_PBM; break;
  72.     case 'R':    outtype = FMT_RLE; break;
  73.     case 'S':    outtype = FMT_SUN; break;
  74.     case 'T':    outtype = FMT_TIFF; break;
  75.     case 'X':    outtype = FMT_X11; break;
  76.     case 'Z':    outtype = FMT_PCX; break;
  77.         default:        fprintf (stderr, "%s\n", USAGE);
  78.                         exit (1);
  79.       }
  80.     }
  81.   }
  82.   
  83.   /* Clear the memory pointers so alloc_fbm won't be confused */
  84.   input.cm  = input.bm  = (unsigned char *) NULL;
  85.   output.cm = output.bm = (unsigned char *) NULL;
  86.  
  87.   /* Read the image and clean it */
  88.   if (read_bitmap (&input, (char *) NULL))
  89.   {
  90.     if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  91.     { fprintf (stderr,
  92.            "Can't handle images with %d bits and %d physbits per pixel\n",
  93.            input.hdr.bits, input.hdr.physbits);
  94.       exit (1);
  95.     }
  96.  
  97.     /* Determine output height & width (oh*ow <= size) */
  98.     h = input.hdr.rows;
  99.     w = input.hdr.cols;
  100.     k = input.hdr.planes;
  101.  
  102.     fprintf (stderr,
  103.          "Edge detect\"%s\", Black-trip %2d [%dx%dx%d]\n",
  104.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  105.          blacktrp, w, h, k);
  106.  
  107.     /* Edge detect the image using a digitial Laplacian */
  108.     if (findedge_fbm (&input, &output, blacktrp) &&
  109.         write_bitmap (&output, stdout, outtype))
  110.     { exit (0); }
  111.   }
  112.   
  113.   exit (1);
  114. }
  115.